package com.jyx.chain.filterchain;

import java.util.ArrayList;
import java.util.List;

import com.jyx.chain.filter.Filter;

/**
 * 一个完整的filterCahin
 * @author Administrator
 *
 */
public class FilterChain implements Filter {

	private List<Filter> filters = new ArrayList<Filter>();
	
	/**
	 * 添加一个过滤器
	 * @param f
	 */
	public FilterChain addFilter(Filter f){
		filters.add(f);
		return this;
	}
	
	/**
	 * 执行自己的过滤方法
	 * @param msg
	 * @return
	 */
	public String doFilter(String msg){
		for (Filter f : filters) {
			msg = f.doFilter(msg);
		}
		return msg;
	}
	
}
